package com.gold.rabbitmqdemo.study4;

import com.gold.rabbitmqdemo.util.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ExchangeProducer {
    /** 交互机名称 */
    private static final String  EXCHANGE_NAME="test_exchange_fanout";
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection= ConnectionUtils.getConnection();
        Channel channel=connection.createChannel();
        //声明交换机：fanout 分发
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        //发送消息到交换机：若未有队列绑定交换机前发送消息，消息会丢失。因为交换机没有存储能力，只有队列可存储。
        String msg="hello faout";
        channel.basicPublish(EXCHANGE_NAME,"",null,msg.getBytes());
        System.out.println("exchange producer send msg:"+msg);

        channel.close();
        connection.close();
    }
}
